package cn.iocoder.yudao.module.crossborder.order.service.orderpayment;

import cn.hutool.core.collection.CollUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.crossborder.order.controller.admin.orderpayment.vo.*;
import cn.iocoder.yudao.module.crossborder.order.dal.dataobject.orderpayment.OrderPaymentDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.crossborder.order.dal.mysql.orderpayment.OrderPaymentMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList;
import static cn.iocoder.yudao.module.crossborder.order.enums.ErrorCodeConstants.*;
import static cn.iocoder.yudao.module.crossborder.enums.CrossBorderConstants.*;
import cn.iocoder.yudao.module.crossborder.order.enums.PaymentStatusEnum;
import cn.iocoder.yudao.module.crossborder.order.enums.PaymentTypeEnum;

/**
 * 跨境电商订单支付 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class OrderPaymentServiceImpl implements OrderPaymentService {

    @Resource
    private OrderPaymentMapper orderPaymentMapper;

    @Override
    public Long createOrderPayment(OrderPaymentSaveReqVO createReqVO) {
        // 插入
        OrderPaymentDO orderPayment = BeanUtils.toBean(createReqVO, OrderPaymentDO.class);
        orderPaymentMapper.insert(orderPayment);

        // 返回
        return orderPayment.getId();
    }

    @Override
    public void updateOrderPayment(OrderPaymentSaveReqVO updateReqVO) {
        // 校验存在
        validateOrderPaymentExists(updateReqVO.getId());
        // 更新
        OrderPaymentDO updateObj = BeanUtils.toBean(updateReqVO, OrderPaymentDO.class);
        orderPaymentMapper.updateById(updateObj);
    }

    @Override
    public void deleteOrderPayment(Long id) {
        // 校验存在
        validateOrderPaymentExists(id);
        // 删除
        orderPaymentMapper.deleteById(id);
    }

    @Override
        public void deleteOrderPaymentListByIds(List<Long> ids) {
        // 删除
        orderPaymentMapper.deleteByIds(ids);
        }


    private void validateOrderPaymentExists(Long id) {
        if (orderPaymentMapper.selectById(id) == null) {
            throw exception(ORDER_PAYMENT_NOT_EXISTS);
        }
    }

    @Override
    public OrderPaymentDO getOrderPayment(Long id) {
        return orderPaymentMapper.selectById(id);
    }

    @Override
    public PageResult<OrderPaymentDO> getOrderPaymentPage(OrderPaymentPageReqVO pageReqVO) {
        return orderPaymentMapper.selectPage(pageReqVO);
    }

}